package com.yc.yyds.dao;

import com.yc.yyds.util.DBHelper;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Userdao {
    public List<Map<String,Object>>qurey(){
        String  sql="select * from user where status=1";
        return DBHelper.selectListMap(sql);
    }
    public List<Map<String,Object>>qurey(String username ){
        String sql="select * from user where status=1";
        List<Object> params=new ArrayList<>();

        if(username!=null &&username.trim().isEmpty()==false){
            sql+=" and username like concat('%',?,'%')";
            params.add(username);
        }
        return  DBHelper.selectListMap(sql,params.toArray());
    }
    public void create( String username,String userzh,String pwd,String phone,String time,String email ,String isvip,String image){
        String sql="insert into user (username,userzh,pwd,phone,time,email,isvip,image) values (?,?,?,?,?,?,?,?)";
        DBHelper.update(sql,username,userzh,pwd,phone,Date.valueOf(time),email,isvip,image);
    }
    public void modify(String userid,String username,String userzh,String pwd,String phone,String time,String email,String isvip,String image){
        String sql="update user set username=?, userzh=?,pwd=?,phone=?,time=?,email=?,isvip=?,image=? where userid=?";
        DBHelper.update(sql,username,userzh,pwd,phone,Date.valueOf(time),email,isvip,image,userid);
    }
    public void modify1(String userid,String freeze){
        String sql="update user set freeze=? where userid=?";
        DBHelper.update(sql,freeze,userid);
    }
    //物理删除
    public void remove(String userid){
        String sql="delete from user where userid=?";
        DBHelper.update(sql,userid);
    }
    //逻辑删除
    public  void remove1(String userid){
        String sql="update user set status = 0 where userid=?";
        DBHelper.update(sql,userid);
    }
    public Map<String,Object>  qureys(String userzh){
        String sql="select freeze from user where userzh=?";
       return DBHelper.selectOneMap(sql,userzh);
    }
    public Map<String,Object> login(String userzh,String pwd){
        String sql = " select * from user where userzh = ? and pwd = ? and freeze=1" ;
        return DBHelper.selectOneMap(sql,userzh,pwd);
    }
    public Map<String,Object> username(String userzh){
        String sql="select username from user where userzh=?";
        return DBHelper.selectOneMap(sql,userzh);
    }

}
